using Microsoft.AspNetCore.Mvc;
using JTZY.Model.Order.Dto;
using JTZY.Model.Order;
using JTZY.Service.Order.IOrderService;
using JTZY.Admin.WebApi.Filters;

//创建时间：2025-02-23
namespace JTZY.Admin.WebApi.Controllers.Order
{
    /// <summary>
    /// 换货明细
    /// </summary>
    [Verify]
    [Route("order/Exchangedetail")]
    public class ExchangedetailController : BaseController
    {
        /// <summary>
        /// 换货明细接口
        /// </summary>
        private readonly IExchangedetailService _ExchangedetailService;

        public ExchangedetailController(IExchangedetailService ExchangedetailService)
        {
            _ExchangedetailService = ExchangedetailService;
        }

        /// <summary>
        /// 查询换货明细列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "exchangedetail:list")]
        public IActionResult QueryExchangedetail([FromQuery] ExchangedetailQueryDto parm)
        {
            var response = _ExchangedetailService.GetList(parm);
            return SUCCESS(response);
        }

        /// <summary>
        /// 换货明细
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpPost("getdeatils")]
        [ActionPermissionFilter(Permission = "exchangedetail:list")]
        public IActionResult GetExchangedetails([FromBody] QueryDetailsDto parm)
        {
            var response = _ExchangedetailService.GetExchangedetails(parm);
            return SUCCESS(response);
        }

        /// <summary>
        /// 查询换货明细详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "exchangedetail:query")]
        public IActionResult GetExchangedetail(long Id)
        {
            var response = _ExchangedetailService.GetInfo(Id);
            
            var info = response.Adapt<ExchangedetailDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加换货明细
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "exchangedetail:add")]
        [Log(Title = "换货明细", BusinessType = BusinessType.INSERT)]
        public IActionResult AddExchangedetail([FromBody] ExchangedetailDto parm)
        {
            var modal = parm.Adapt<Exchangedetail>().ToCreate(HttpContext);

            var response = _ExchangedetailService.AddExchangedetail(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新换货明细
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "exchangedetail:edit")]
        [Log(Title = "换货明细", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateExchangedetail([FromBody] ExchangedetailDto parm)
        {
            var modal = parm.Adapt<Exchangedetail>().ToUpdate(HttpContext);
            var response = _ExchangedetailService.UpdateExchangedetail(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除换货明细
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete/{ids}")]
        [ActionPermissionFilter(Permission = "exchangedetail:delete")]
        [Log(Title = "换货明细", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteExchangedetail([FromRoute]string ids)
        {
            var idArr = Tools.SplitAndConvert<long>(ids);

            return ToResponse(_ExchangedetailService.Delete(idArr));
        }

    }
}